package com.taptech.doufu.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.taptech.doufu.R
import com.taptech.doufu.constant.Constant
import com.taptech.doufu.model.novel.bean.NovelCategoryBean
import com.taptech.doufu.ui.activity.NovelDetailsActivity
import com.taptech.doufu.util.GlideUtil
import com.taptech.doufu.util.TagsUtil
import kotlinx.android.synthetic.main.adapter_novle_category_layout.view.*

class NovelCategoryChildAdapter(context:Context): BaseRecyclerAdappter<NovelCategoryBean,NovelCategoryChildAdapter.ViewHolder>(context){

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.adapter_novle_category_layout,null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val item = dataList[position]
        holder.itemView.tvTitle.text = item.title
        holder.itemView.tvDesc.text = item.des
        holder.itemView.tvAuthor.text = item.author
        GlideUtil.displayRoundImage(holder.itemView.ivCover, item.images[0].imgUrl,5,R.drawable.img_default_loading_l)
//        holder.itemView.ivVip.visibility = if (item.is_vip>0) View.VISIBLE else View.GONE

        val tags = item.tags
        if (tags.isNotEmpty() && tags.size>0) {
            holder.itemView.tvTag1.visibility = View.VISIBLE
            holder.itemView.tvTag1.setOnClickListener {
                TagsUtil.openWeexTagActivity(mContext, tags[0].name, Constant.OBJECT_TYPE_NOVEL, "")
            }
            holder.itemView.tvTag1.text = tags[0].name
            if (tags.size > 1) {
                holder.itemView.tvTag2.visibility = View.VISIBLE
                holder.itemView.tvTag2.setOnClickListener {
                    TagsUtil.openWeexTagActivity(mContext, tags[1].name, Constant.OBJECT_TYPE_NOVEL, "")
                }
                holder.itemView.tvTag2.text = tags[1].name
            }else{
                holder.itemView.tvTag2.visibility = View.GONE
            }
        }else{
            holder.itemView.tvTag1.visibility = View.GONE
            holder.itemView.tvTag2.visibility = View.GONE
        }

        holder.itemView.setOnClickListener {
            NovelDetailsActivity.startActivity(mContext,item.id)
        }
    }

    class ViewHolder(view: View): RecyclerView.ViewHolder(view)
}